//
//  YMFUserInfoViewController.swift
//  FlyingPigeon
//
//  Created by yang on 2019/5/30.
//  Copyright © 2019年 a. All rights reserved.
//

import Foundation
import UIKit


class YMFUserInfoViewController: UIViewController {
    let tableView = UITableView()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        navigationItem.title = "个人资料"
        
        tableView.dataSource = self
        tableView.delegate = self
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
        tableView.backgroundColor = UIColor(red: 245 / 255.0, green: 245 / 255.0, blue: 245 / 255.0, alpha: 1)
        tableView.frame = CGRect(x: 0, y: 0, width: view.bounds.width, height: view.bounds.height - 64)
        view.addSubview(tableView)
        
    }
}


extension YMFUserInfoViewController: UITableViewDelegate, UITableViewDataSource {
//    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
//
//        let view = UIView(frame: CGRect(x: 0, y: 0, width: tableView.bounds.width, height: 130))
//        view.backgroundColor = UIColor(red: 96 / 255.0, green: 149 / 255.0 , blue: 223 / 255.0, alpha: 1)
//
//        let userImageView = UIImageView(frame: CGRect(x: 10, y: 0, width: 78, height: 78))
//        userImageView.image = UIImage(named: "userImage")
//        userImageView.center = CGPoint(x: userImageView.center.x, y: view.bounds.height * 0.6)
//        view.addSubview(userImageView)
//
//        let userName = UILabel(frame: CGRect(x: userImageView.frame.maxX + 10, y: userImageView.center.y - 30, width: 200, height: 21))
//        userName.font = UIFont.systemFont(ofSize: 14)
//        userName.textColor = UIColor.white
//        userName.text = "王一鸣"
//        view.addSubview(userName)
//
//        let userInfo = UILabel(frame: CGRect(x: userImageView.frame.maxX + 10, y: userImageView.center.y , width: 200, height: 21))
//        userInfo.font = UIFont.systemFont(ofSize: 14)
//        userInfo.textColor = UIColor.white
//        userInfo.text = "车龄： 3年"
//        view.addSubview(userInfo)
//
//
//        return view
//    }
//
//    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
//        return 130
//    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 4
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
        
        if indexPath.row == 0 {
            let imageView = UIImageView(image: UIImage(named: "userImage"))
            imageView.bounds = CGRect(x: 0, y: 0, width: 40, height: 40)
            cell?.accessoryView = imageView
            cell?.textLabel?.text = "头像"
        } else {
            let label = UILabel()
            label.textColor = UIColor.lightGray
            if indexPath.row == 1 {
                label.text = "王一鸣"
                cell?.textLabel?.text = "昵称"
            } else if indexPath.row == 2 {
                label.text = "男"
                cell?.textLabel?.text = "性别"
            } else if indexPath.row == 3 {
                label.text = "3年"
                cell?.textLabel?.text = "车龄"
            }
            label.sizeToFit()
            cell?.accessoryView = label
        }
        
        return cell!
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    
        tableView.deselectRow(at: indexPath, animated: true)
        
        
        
    }
}

